home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1993 November / JCSM Shareware Collection - 1993-11.iso / cl720 / qbnws31j.lzh / TABLDEMO.BAS < prev    next >
BASIC Source File  |  1993-07-23  |  21KB  |  429 lines

  1. '*********************************************************************
  2. '*                                                                   *
  3. '*      PROGRAMNAME :   TABLDEMO.BAS                                 *
  4. '*                                                                   *
  5. '*      DESCRIPTION :   this program shows you how to declare a      *
  6. '*                      table,  how to write it onto the screen,     *
  7. '*                      how to select an item and how to reenter     *
  8. '*                      the table.                                   *
  9. '*                                                                   *
  10. '*      REMARKS     :   names of constants in include modules are    *
  11. '*                      in dutch language foreign users may alter    *
  12. '*                      names as desired                             *
  13. '*                                                                   *
  14. '*      REV   DATE      HISTORY                                      *
  15. '*      0.0   18JAN92   Bernard Veerman - version for QB-NEWS        *
  16. '*                                                                   *
  17. '*********************************************************************
  18.  
  19. DEFINT A-Z
  20.  
  21. COMMON SHARED TablDefs()
  22. COMMON SHARED TOP, ROW, COL, HGT, WID, SF, SB, BF, BB, PTR, CUR, BTP
  23. '
  24. '       subprograms to be called by user
  25. '
  26. DECLARE SUB TABLOPEN (TNR, TOP, ROW, COL, HGT, WID, SF, SB, BF, BB, TY$)
  27. DECLARE SUB TABLSLCT (TNR, Table$(), Entry$)
  28. '
  29. '       subprogram to be called by subprogram TABLSLCT
  30. '
  31. DECLARE SUB DRAWBOX (ROW, COL, VRT, HOR, TY$)
  32. DECLARE SUB TABLDISP (TNR, PTR, Table$())
  33. DECLARE SUB TABLLINE (TNR, CUR, Video$)
  34. DECLARE SUB TABLLOAD (TNR)
  35. '
  36. '       include modules for keyboard and colors
  37. '
  38. '       $INCLUDE: 'VZKEYBRD.BAS'
  39. '       $INCLUDE: 'VZCOLORS.BAS'
  40.        
  41.         DIM TablDefs(6, 12)
  42.  
  43. '---------------------------------------------------------------------
  44. '------- now forget all previous work and look at this coding --------
  45. '------------- first, declare any matrix and fill it up --------------
  46. '------- with anything you want (file, table, directory etc.) --------
  47. '--------------- than just move thru the table and pick --------------
  48. '---------------------------------------------------------------------
  49.  
  50. CLS
  51. DATA Ford,Chevrolet,Oldsmobile,Cadillac,Chrysler,Pontiac,Edsel
  52. DATA Studebaker,Skoda,Honda,Mazda,Volvo,Volkswagen,Toyota,Peugeot
  53.  
  54. DATA Washington,Oregon,Idaho,Montana,Wyoming,North Dakota,South Dakota
  55. DATA Nebraska,Minnesota,Wisconsin,Iowa,Illinois,Indiana,Mitchigan,Ohio
  56. DATA Pennsylvania,New York,Maine,California,Nevada,Utah,Colorado
  57. DATA Arizona,New Mexico,Kansas,Missouri,Kentucky,West Virginia
  58. DATA Virginia,Texas,Oklahoma,Arkansas,Louisiana,Tennessee
  59. DATA North Carolina,South Carolina,Mississippi,Alabama,Georgia,Florida
  60. DATA Hawai,Alaska,Vermont,New Hampshire,Massachusetts,Connecticut
  61. DATA Jersey,Maryland,Rhode Island,Delaware
  62.  
  63. DIM Cars$(15)                           'just some cars
  64. FOR X = 1 TO 15                         'get their names
  65.    READ Cars$(X)                        'fill table
  66. NEXT                                    'done ?
  67.  
  68. DIM States$(50)                         'I did my best to get all of
  69. FOR X = 1 TO 50                         'them 51 states, but... oops
  70.    READ States$(X)                      'I can't figure out which one
  71. NEXT                                    'is missing. Sorry for that!
  72.  
  73. DIM YN$(2)                              'just another example
  74. YN$(1) = "  Yes  "
  75. YN$(2) = "  No   "
  76.  
  77. TABLOPEN 1, 15, 8, 30, 10, 30, WT, ZW, ZW, WT, "d"
  78. TABLOPEN 2, 50, 4, 10, 16, 25, ZW, WT, WT + HLDR, ZW, "s"
  79. TABLOPEN 3, 2, 19, 70, 4, 9, WT, ZW, ZW + BLNK, WT, "s"
  80.  
  81. TABLSLCT 1, Cars$(), YourPick$          'table = CARS ----->>>----+
  82. TABLSLCT 2, States$(), Bingo$           'table = STATES --->>>--+ |
  83. TABLSLCT 3, YN$(), NowWhat$             'table = YN ------->>>--|-|-+
  84.                                         '                       | | |
  85. CLS                                     'clear screen           | | |
  86. FOR X = 1 TO 24                         'paint background       | | |
  87.    PRINT STRING$(80, CHR$(176));        '                       | | |
  88. NEXT                                    '                       | | |
  89. Text$ = " any key to re-enter table "   '                       | | |
  90. LOCATE 12, (80 - LEN(Text$)) \ 2, 0     '                       | | |
  91. PRINT Text$;                            '                       | | |
  92. X$ = INPUT$(1)                          'wait for keyboard      | | |
  93.                                         '                       | | |
  94. TABLSLCT 2, States$(), Bingo$           'RE-ENTER TABLE ---<<<--+ | |
  95. TABLSLCT 1, Cars$(), YourPick$          'RE-ENTER TABLE ---<<<----+ |
  96.                                         '                           |
  97. LOCATE 24, 1                            '                           |
  98. PRINT SPACE$(80); ;                     '                           |
  99. LOCATE 24, 1                            '                           |
  100. PRINT " your pick : "; YourPick$;       '                           |
  101.                                         '                           |
  102. TABLSLCT 3, YN$(), OK$                  'done, yes anyway -<<<------+
  103. COLOR WT, ZW                            'reset white on black
  104. CLS
  105.  
  106. 'page
  107. '
  108. SUB DRAWBOX (ROW, COL, VRT, HOR, TY$)
  109.  
  110. '*********************************************************************
  111. '*                                                                   *
  112. '*      PROGRAMNAME :   DRAWBOX, draws a box on the screen. The      *
  113. '*                      contents of the box will not be destroyed.   *
  114. '*                                                                   *
  115. '*      PARAMETERS  :   ROW = valid row from 1 thr 25                *
  116. '*                      COL = valid column from 1 thru 80            *
  117. '*                      VRT = heigth of box (vertical)               *
  118. '*                      HOR = length of box (horizontal)             *
  119. '*                      TY$ = line type, d= double, s = single       *
  120. '*                            where single is the default value      *
  121. '*                                                                   *
  122. '*      REMARKS     :   validation of line/columns/heigth/width      *
  123. '*                      is supposed to be done by the programmer     *
  124. '*                                                                   *
  125. '*      VER   DATE      HISTORY                                      *
  126. '*      0.0   18JAN92   Bernard Veerman - version for QB NEWS        *
  127. '*                                                                   *
  128. '*********************************************************************
  129.  
  130. IF UCASE$(TY$) = "D" THEN                       'double lines ?
  131.    LTOP$ = CHR$(DCTL): RTOP$ = CHR$(DCTR)       'top left/right
  132.    LBOT$ = CHR$(DCBL): RBOT$ = CHR$(DCBR)       'bottom left/right
  133.    HLIN$ = CHR$(DLHO): VLIN$ = CHR$(DLVE)       'line hor/vert
  134. ELSE                                            'single line (default)
  135.    LTOP$ = CHR$(SCTL): RTOP$ = CHR$(SCTR)       'top left/right
  136.    LBOT$ = CHR$(SCBL): RBOT$ = CHR$(SCBR)       'bottom left/right
  137.    HLIN$ = CHR$(SLHO): VLIN$ = CHR$(SLVE)       'line hor/vertical
  138. END IF
  139.  
  140. HORL$ = STRING$(HOR - 2, HLIN$)         'make horizontal line
  141. COLRT = COL + HOR - 1                   'calc right column
  142.  
  143. LOCATE ROW, COL                         'top left location
  144. PRINT LTOP$; HORL$; RTOP$;              'diplay top line
  145. LOCATE ROW + VRT - 1, COL               'bottom left location
  146. PRINT LBOT$; HORL$; RBOT$;              'display bottom line
  147.  
  148. FOR X = ROW + 1 TO ROW + VRT - 2        'fill in the sides
  149.    LOCATE X, COL: PRINT VLIN$;          'left side
  150.    LOCATE X, COLRT: PRINT VLIN$;        'right side
  151. NEXT                                    'done ?
  152.  
  153. END SUB
  154.  
  155. 'page
  156. '
  157. SUB TABLDISP (TNR, PTR, Table$())
  158.  
  159. '*********************************************************************
  160. '*                                                                   *
  161. '*      PROGRAMNAME :   TABLDISP, displays a table                   *
  162. '*                                                                   *
  163. '*      PARAMETERS  :   TNR = table number                           *
  164. '*                      PTR = record pointer                         *
  165. '*                      Table$() = table name                        *
  166. '*                                                                   *
  167. '*      VER   DATE      HISTORY                                      *
  168. '*      0.0   18JAN92   Bernard Veerman - version for QB NEWS        *
  169. '*                                                                   *
  170. '*********************************************************************
  171.  
  172. TABLLOAD TNR                            'get parms
  173.  
  174. XPTR = PTR                              'temp rec pointer
  175. XROW = ROW                              'temp line pointer
  176.  
  177. DO                                      'display table
  178.    LOCATE XROW, COL                     'position cursor
  179.    PRINT LEFT$(Table$(XPTR), WID);      'display entry
  180.    IF LEN(Table$(XPTR)) < WID THEN      'trailing blanks
  181.       PRINT SPACE$(WID - LEN(Table$(XPTR)));
  182.    END IF
  183.  
  184.    XROW = XROW + 1                      'incr display row
  185.    XPTR = XPTR + 1                      'incr record pointer
  186.  
  187. LOOP UNTIL XROW - ROW = HGT             'all lines displayed ?
  188.  
  189. END SUB
  190.  
  191. 'page
  192. '
  193. SUB TABLLINE (TNR, CUR, Video$)
  194.  
  195. '*********************************************************************
  196. '*                                                                   *
  197. '*      PROGRAMNAME :   TABLLINE, displays a line in the table       *
  198. '*                                                                   *
  199. '*      PARAMETERS  :   TNR = table number                           *
  200. '*                      CUR = current line in table                  *
  201. '*                      Video$ = normal or reversed video            *
  202. '*                                                                   *
  203. '*      REMARKS     :   fore- and background colors from TablDefs    *
  204. '*                                                                   *
  205. '*      VER   DATE      HISTORY                                      *
  206. '*      0.0   18JAN92   Bernard Veerman - version for QB NEWS        *
  207. '*                                                                   *
  208. '*********************************************************************
  209.  
  210. TABLLOAD TNR                            'get parms
  211.  
  212. ABSROW = ROW + CUR - 1                  'calc absolute display line
  213. LOCATE ABSROW, COL                      'position cursor
  214.  
  215. ThisLine$ = SPACE$(WID)                 'init string
  216. FOR ThisChar = 1 TO WID                 'read screen
  217.    MID$(ThisLine$, ThisChar) = CHR$(SCREEN(ABSROW, COL + ThisChar - 1))
  218. NEXT
  219.  
  220. IF UCASE$(Video$) = "N" THEN            'normal video ?
  221.    COLOR SF, SB                         'set screen colors
  222.    PRINT ThisLine$;                     'display line at ABSROW, COL
  223. ELSE                                    'reversed video
  224.    COLOR BF, BB                         'set bar colors
  225.    PRINT ThisLine$;                     'display line at ABSROW, COL
  226.    COLOR SF, SB                         'set screen colors
  227. END IF                                  'done
  228.  
  229. END SUB
  230.  
  231. 'page
  232. '
  233. SUB TABLLOAD (TNR)
  234.  
  235. '*********************************************************************
  236. '*                                                                   *
  237. '*      PROGRAMNAME :   TABLLOAD, loads parms for a table            *
  238. '*                      CUR + PTR are variables and are passed       *
  239. '*                      as parameters when called                    *
  240. '*                                                                   *
  241. '*      PARAMETERS  :   TNR = table number                           *
  242. '*                                                                   *
  243. '*      VER   DATE      HISTORY                                      *
  244. '*      0.0   18JAN92   Bernard Veerman - version for QB NEWS        *
  245. '*                                                                   *
  246. '*********************************************************************
  247.  
  248. TOP = TablDefs(TNR, 1)                  'table top
  249. ROW = TablDefs(TNR, 2)                  'display row
  250. COL = TablDefs(TNR, 3)                  'display column
  251. HGT = TablDefs(TNR, 4)                  'height
  252. WID = TablDefs(TNR, 5)                  'width
  253. BTP = TablDefs(TNR, 12)                 'box type
  254.  
  255. SF = TablDefs(TNR, 6)                   'screen foreground
  256. SB = TablDefs(TNR, 7)                   'screen background
  257. BF = TablDefs(TNR, 8)                   'bar foreground
  258. BB = TablDefs(TNR, 9)                   'bar background
  259.  
  260. END SUB
  261.  
  262. 'page
  263. '
  264. SUB TABLOPEN (TNR, TOP, ROW, COL, HGT, WID, SF, SB, BF, BB, TY$)
  265.  
  266. '*********************************************************************
  267. '*                                                                   *
  268. '*      PROGRAMNAME :   TABLOPEN, saves the parameters of a table    *
  269. '*                      for further use. Re-entry is made possible   *
  270. '*                                                                   *
  271. '*      PARAMETERS  :   TNR = tablenumber 1 thru 6 (see TABLDEFS)    *
  272. '*                      TOP = table size                             *
  273. '*                      ROW = display row                            *
  274. '*                      COL = display column                         *
  275. '*                      HGT = table heigth (lines 1-25)              *
  276. '*                      WID = table width (columns 1-80)             *
  277. '*                      SF  = screen color foreground                *
  278. '*                      SB  = screen color background                *
  279. '*                      BF  = bar color foreground                   *
  280. '*                      BB  = bar color background                   *
  281. '*                      TY$ = line type for drawbox                  *
  282. '*                            "" = no box, s = single, d = double    *
  283. '*                                                                   *
  284. '*      REMARKS     :   validation of line/columns/heigth/width      *
  285. '*                      is supposed to be done by the programmer     *
  286. '*                                                                   *
  287. '*      VER   DATE      HISTORY                                      *
  288. '*      0.0   18JAN92   Bernard Veerman - version for QB NEWS        *
  289. '*                                                                   *
  290. '*********************************************************************
  291.  
  292. IF LEN(TY$) = 0 THEN                            'no box wanted
  293.    TablDefs(TNR, 12) = 0                        'make boxtype 0
  294. ELSE                                            'box wanted
  295.    TablDefs(TNR, 12) = INSTR("SD", UCASE$(TY$)) 'make boxtype 1 or 2
  296.    ROW = ROW + 1: COL = COL + 1                 'adjust row & column
  297.    HGT = HGT - 2: WID = WID - 2                 'adjust heigth & width
  298. END IF
  299.  
  300. TablDefs(TNR, 1) = TOP                          'table size
  301. TablDefs(TNR, 2) = ROW                          'display row
  302. TablDefs(TNR, 3) = COL                          'display column
  303. TablDefs(TNR, 4) = HGT                          'table height
  304. TablDefs(TNR, 5) = WID                          'table width
  305. TablDefs(TNR, 6) = SF                           'screen foreground
  306. TablDefs(TNR, 7) = SB                           'screen background
  307. TablDefs(TNR, 8) = BF                           'bar foreground
  308. TablDefs(TNR, 9) = BB                           'bar background
  309. TablDefs(TNR, 10) = 1                           'init record pointer
  310. TablDefs(TNR, 11) = 1                           'init current line
  311.  
  312. END SUB
  313.  
  314. 'page
  315. '
  316. SUB TABLSLCT (TNR, Table$(), Entry$)
  317.  
  318. '*********************************************************************
  319. '*                                                                   *
  320. '*      PROGRAMNAME :   TABLSLCT, select entry from table            *
  321. '*                                                                   *
  322. '*      PARAMETERS  :   TNR      = table number                      *
  323. '*                      Table$() = table name                        *
  324. '*                      Entry$   = selected entry or <ESCAPE>        *
  325. '*                                                                   *
  326. '*      REMARKS     :   validation of line/columns/heigth/width      *
  327. '*                      is supposed to be done by the programmer     *
  328. '*                                                                   *
  329. '*      VER   DATE      HISTORY                                      *
  330. '*      0.0   18JAN92   Bernard Veerman - version for QB NEWS        *
  331. '*                                                                   *
  332. '*********************************************************************
  333.  
  334. TABLLOAD TNR                            'get parms
  335. PTR = TablDefs(TNR, 10)                 'copy record pointer
  336. CUR = TablDefs(TNR, 11)                 'copy line pointer
  337.  
  338. COLOR SF, SB                            'set colors (for DRAWBOX)
  339. LOCATE , , 0                            'hide cursor
  340.  
  341. IF TOP < HGT THEN HGT = TOP             'safety first
  342. IF BTP > 0 THEN                         'box wanted ?
  343.    TY$ = MID$("SD", BTP, 1)             'get box type
  344.    DRAWBOX ROW - 1, COL - 1, HGT + 2, WID + 2, TY$
  345. END IF
  346.  
  347. TABLDISP TNR, PTR, Table$()             'display the table
  348. TABLLINE TNR, CUR, "R"                  'first display line
  349.  
  350. DO                                      'this is the main loop
  351.    DO                                   'wait for a character
  352.       C$ = INKEY$                       'read keyboard
  353.    LOOP UNTIL C$ <> ""                  'anything yet ?
  354.   
  355.    TABLLINE TNR, CUR, "N"               'normal video
  356.  
  357.    SELECT CASE C$                       'what have we got ?
  358.   
  359.       CASE CHR$(Entr)                   'enter
  360.          Entry$ = Table$(PTR + CUR - 1) 'copy entry from table
  361.      
  362.       CASE CHR$(Escp)                   'escape
  363.          Entry$ = "<ESCAPE>"            'easy if you're interested
  364.      
  365.       CASE CHR$(Null) + CHR$(CurH)      'cursor home current page
  366.          CUR = 1                        'goto first line in page
  367.  
  368.       CASE CHR$(Null) + CHR$(CurE)      'cursor end current page
  369.          CUR = HGT                      'goto last line in page
  370.  
  371.       CASE CHR$(Null) + CHR$(CtlH)      'cursor home first page
  372.          CUR = 1                        'reset line pointer
  373.          PTR = 1                        'reset record pointer
  374.          TABLDISP TNR, PTR, Table$()    'display first page
  375.  
  376.       CASE CHR$(Null) + CHR$(CtlE)      'cursor end last page
  377.          CUR = HGT                      'set line pointer
  378.          PTR = TOP - HGT + 1            'set record pointer
  379.          TABLDISP TNR, PTR, Table$()    'display last page
  380.  
  381.       CASE CHR$(Null) + CHR$(PgUp)      'page up
  382.          PTR = PTR - HGT                'decr pagesize
  383.          IF PTR < 1 THEN                'past begin of file ?
  384.             CUR = 1                     'reset line pointer
  385.             PTR = 1                     'reset record pointer
  386.          END IF                         '
  387.          TABLDISP TNR, PTR, Table$()    'display previous page
  388.  
  389.       CASE CHR$(Null) + CHR$(PgDn)      'page down
  390.          PTR = PTR + HGT                'incr pagesize
  391.          IF PTR > TOP - HGT + 1 THEN    'past end of file ?
  392.             CUR = HGT                   'set line pointer
  393.             PTR = TOP - HGT + 1         'set record pointer
  394.          END IF                         '
  395.          TABLDISP TNR, PTR, Table$()    'display next page
  396.      
  397.       CASE CHR$(Null) + CHR$(ArrU)      'arrow up + scroll
  398.          CUR = CUR - 1                  'decr line pointer
  399.          IF CUR < 1 THEN                'out of page bound ?
  400.             CUR = 1                     'reset line pointer
  401.             IF PTR > 1 THEN             'valid record pointer ?
  402.                PTR = PTR - 1            'decr record pointer
  403.                TABLDISP TNR, PTR, Table$()
  404.             END IF
  405.          END IF
  406.  
  407.       CASE CHR$(Null) + CHR$(ArrD)      'arrow down + scroll
  408.          CUR = CUR + 1                  'incr line pointer
  409.          IF CUR > HGT THEN              'out of page bound ?
  410.             CUR = HGT                   'set line pointer
  411.             IF TOP - PTR >= HGT THEN    'valid record pointer ?
  412.                PTR = PTR + 1            'incr record pointer
  413.                TABLDISP TNR, PTR, Table$()
  414.             END IF
  415.          END IF
  416.  
  417.    END SELECT
  418.  
  419.    TABLLINE TNR, CUR, "R"
  420.  
  421. LOOP UNTIL C$ = CHR$(Entr) OR C$ = CHR$(Escp)
  422.  
  423. LOCATE , , 1                            'unhide cursor
  424. TablDefs(TNR, 10) = PTR                 'save record pointer
  425. TablDefs(TNR, 11) = CUR                 'save current line
  426.  
  427. END SUB
  428.  
  429.